import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { VantResolver } from '@vant/auto-import-resolver';
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'; 
// https://vitejs.dev/config/
export default defineConfig({
  base: '/mobile/',
  plugins: [
    vue(),
    // 按需导入element-ui
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: "sass"
        }),
        VantResolver()
      ],
    }),
    createSvgIconsPlugin({
      // 需要自动导入的 svg 文件目录（可自行修改）我的路径如下图所示
      iconDirs: [path.resolve(process.cwd(), "src/assets/icon/svg")],
      // 执行icon name的格式（可自行修改）
      symbolId: "icon-[dir]-[name]",
    })
  ],
  // 服务配置
  server: {
    host: '0.0.0.0',
    open: true,// 自动在浏览器打开    
    https: false,// 是否开启 https                        
    cors: true, // 默认启用并允许任何源
    proxy: {
      '/api': {
        target: '',   //代理接口
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      },
      '/ys-amp-web': {
        target: '',   //代理接口
        changeOrigin: true,
      },
    }
  },
  resolve: {
    alias: {
      vue: "vue/dist/vue.esm-bundler.js",
      '@': path.resolve(__dirname, 'src'), //配置@路径
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/styles/element.scss" as *;@use "@/assets/styles/vantVar.scss" as *;@use "@/assets/styles/indexVar.scss" as *;`,
      },
    },
    
  },
})
